<template>
  <main id="main" ref="main" style="width: 100%;height:100%;"></main>
</template>

<script lang="js">
const echarts = require("echarts")
export default {
  name: "cBar",
  props: {
    barData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initCarts();
  },
  watch: {
    barData() {
      this.initCarts();
    }
  },
  methods: {
    initCarts() {
      if (!this.chart) this.chart = echarts.init(this.$refs['main']);
      const option = {
        tooltip: {},
        grid: {
          top: '20%',
          left: '0%',
          right: '15%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: ['次均费用', '目标次均费用'],
            axisLabel: {
              textStyle: {
                color: '#484D78',
                fontSize: 12
              }
            },
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false,
            }
          },
        ],
        yAxis: [
          {
            splitArea: {show: false},
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                align: 'right',
                color: '#484D78',
                fontSize: 12
              }
            }
          }
        ],
        series: [
          {
            type: 'bar',
            barWidth: 36,
            emphasis: {
              itemStyle: {
                barBorderWidth: 1,
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowColor: 'rgba(0,0,0,0.5)'
              }
            },
            data: this.barData
          }
        ]
      };
      this.chart.setOption(option);
    }
  }
}
</script>

<style scoped lang="stylus">

</style>
